package com.hdd.biz.operate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdd.biz.operate.dto.LabelInfoRequest;
import com.hdd.biz.operate.dto.LabelListRequest;
import com.hdd.biz.operate.dto.LabelRequest;
import com.hdd.biz.operate.entity.Feedback;
import com.hdd.biz.operate.entity.Label;
import com.hdd.biz.operate.mapper.LabelMapper;
import com.hdd.biz.operate.service.LabelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdd.dto.SuperResponse;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-03-10
 */
@Service
public class LabelServiceImpl extends ServiceImpl<LabelMapper, Label> implements LabelService {

    @Override
    public SuperResponse list(LabelListRequest request) {
        SuperResponse response = new SuperResponse();
        QueryWrapper<Label> wrapper = new QueryWrapper();
        Page<Label> pages = new Page<>(request.getPageNo(),request.getPageSize());
        IPage<Label> mapIPage = baseMapper.selectPage(pages, wrapper);
        List<Label> agents = mapIPage.getRecords();
        response.setItems(agents);
        response.setTotals(pages.getTotal());
        return response;
    }

    @Override
    public SuperResponse info(LabelRequest request) {
        SuperResponse response = new SuperResponse();
        response.setItem(baseMapper.selectById(request.getId()));
        return response;
    }

    @Override
    public SuperResponse delete(LabelRequest request) {
        SuperResponse response = new SuperResponse();
        Label label = new Label();
        label.setId(request.getId());
        label.setDelFlag(1);
        baseMapper.updateById(label);
        return response;
    }

    @Override
    public SuperResponse update(LabelInfoRequest request) {
        SuperResponse response = new SuperResponse();
        Label label = new Label();
        label.setId(request.getId());
        label.setName(request.getName());
        label.setDelFlag(request.getDelFlag());
        label.setParameter(request.getParameter());
        label.setPid(request.getPid());
        label.setType(request.getType());
        baseMapper.updateById(label);
        return response;
    }

    @Override
    public SuperResponse add(LabelInfoRequest request) {
        SuperResponse response = new SuperResponse();
        Label label = new Label();
        label.setName(request.getName());
        label.setDelFlag(request.getDelFlag());
        label.setParameter(request.getParameter());
        label.setPid(request.getPid());
        label.setType(request.getType());
        baseMapper.insert(label);
        return response;
    }
}
